NW 26 - Numerous Small Packet Exchanges Result in Poor TCP Performance
Title Banner


Technical Q&A's


NW 26 - Numerous Small Packet Exchanges Result in Poor TCP Performance (14-May-96)


Q My OT TCP application exchanges a number of small packets of information, which may or may not generate a response from the other side. In some cases, I find that the application delays sending packets and performance is terrible. How can I solve this problem?

A One possible reason for this behavior can be explained by the TCP Delay option. As per the XTI specification, under most circumstances TCP sends data as soon as it is presented. When outstanding data has not yet been acknowledged, it gathers small amounts of output to be sent in a single packet once an acknowledgment is received. For some clients, this packetization may cause significant delays. Use the TCP_NODELAY option to defeat this algorithm. The following code is for a function which demonstrates the use of the OTOptionManagement call to set this option.

#include 			// open transport files			
#include 

/* input: noDelayState - true - nodelay
//						 false - normal delay state
//
// output:	if result less that kOTNoError, then the result of 
//		OTOptionManagement call is returned
//		otherwise, the status value is returned as defined in
//		OpenTransport.h
		T_SUCCESS	= 0x020,	if SUCCESS, then return kOTNoError
		T_FAILURE	= 0x040,
		T_PARTSUCCESS	= 0x100,
		T_READONLY	= 0x200,
		T_NOTSUPPORT	= 0x400
		
*/

OSStatus DoNegotiateNoDelayOption(EndpointRef ep, Boolean noDelayState)

{
	UInt8		buf[kOTFourByteOptionSize];	// define buffer for fourByte
							// Option size
	TOption*	opt;				// option ptr to make items
							// easier to access
	TOptMgmt	req;
	OSStatus	err;
	Boolean	isAsync = false;
	
	opt = (TOption*)buf;			// set option ptr to buffer
	req.opt.buf	= buf;
	req.opt.len	= sizeof(buf);
	req.opt.maxlen = sizeof(buf);		// were using ret for the return
						// result also.
	req.flags	= T_NEGOTIATE;		// negotiate for option

	opt->level	= INET_TCP;		// dealing with an TCP Level function
	opt->name	= TCP_NODELAY;		// define the option to be negotiated
	opt->len	= kOTFourByteOptionSize;
	opt->status = 0;
	*(UInt32*)opt->value = noDelayState;	// set the desired option level, true
						// or false

	if (OTIsSynchronous(ep) == false)	// check whether ep sync or not
	{
		isAsync = true;			// set flag if async
		OTSetSynchronous(ep);		// set endpoint to sync	
	}
				
	err = OTOptionManagement(ep, &req, &req);
	
	if (isAsync == true)			// restore ep state if necessary
		OTSetAsynchronous(ep);

		// if no error then check the option status value
	if (err == kOTNoError)
	{
		if (opt->status != T_SUCCESS) 	// if not T_SUCCESS, return
						// the status
			err = opt->status;
	}	// otherwise return kOTNOError
		
	return err;
}


Technical Support
Technical Q&As
Previous Question | Contents | Next Question

Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help